/**
 * 游戏发射摇杆
 * by wyy
 */
class shootPad extends eui.Component implements eui.UIComponent {
    public target: eui.Rect;
    public range: eui.Rect;
    public player: player;

    private bMove: boolean = false;
    private bShoot: boolean = false;
    public bCanShoot: boolean = true;

    constructor(p) {
        super();
        this.skinName = "resource/eui_skins/game_skins/shootPadSkin.exml";
        this.player = p;
    }
    //摇杆表现和消息
    public move(evt) {
        if (!this.bMove) {
            return;
        }
        let p = new egret.Point(evt.stageX, evt.stageY);
        let center = this.parent.localToGlobal(this.x, this.y);
        let angle = Math.atan2(p.y - center.y, p.x - center.x);
        let dist = egret.Point.distance(p, center);
        if (dist < (this.range.width / 2)) {
            let p = this.globalToLocal(evt.stageX, evt.stageY);
            this.target.x = p.x;
            this.target.y = p.y;
            this.bShoot = false;
            this.player.hideShootLine(false);
        }
        else {
            this.target.x = Math.cos(angle) * (this.range.width / 2) + this.width / 2;
            this.target.y = Math.sin(angle) * (this.range.width / 2) + this.height / 2;
            this.player.showShootLine(angle);
            this.bShoot = true;
        }


    }
    //显示射击摇杆
    public showShootPad(evt) {
        this.player.bMove = false;
        this.x = evt.localX;
        this.y = evt.localY;
        this.visible = true;
        this.bMove = true;
        this.bCanShoot = true;

    }
    public moveEnd(evt) {
        this.visible = false;

        this.bMove = false;
        this.target.x = this.width / 2;
        this.target.y = this.height / 2;

        this.player.hideShootLine(this.bShoot);
        this.bShoot = false;
        this.bCanShoot = false;
    }
}